package cate.game.rank.h;

import cate.game.rank.po.ExtraValueRankSPO;
import cate.game.rank.po.Rank;
import cate.game.rank.vo.RankParam;
import cate.game.role.Role;

public abstract class RankExtraValueHandler<T extends ExtraValueRankSPO> extends RankHandler<T , Rank>{
    /**
     * 默认value大，extraValue大的排前面
     */
    public void record(Role role, int value, long extraValue) {
        record(role, value, extraValue, true);
    }

    /**
     * @see ExtraValueRankSPO.Type
     */
    public void record(Role role, int value, long extraValue, boolean sort) {
        RankParam param = RankParam.build(role);
        long preValue = getRankValue(param, 0);
        synchronized(this){
            getSPO(gameBody).record(role, value, extraValue, sort);
            if(!sort){
                getSPO(gameBody).sort();
            }
            save();
        }
        afterRecord(preValue, param);
    }

    public void mergeRecord(Role role, int value, long extraValue){
        //排行榜合服处理
        if (getIndex(role.getUid()) <= 0 && rankSPO.canInRank(value, extraValue)) {
            record(role, value, extraValue);
        }
    }
}
